package com.zhu.ttwords.view.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import com.zhu.ttwords.bean.WordBean;
import com.zhu.ttwords.view.activity.IStudyActivity;
import com.zhu.ttwords.view.listener.StudyListener;
import com.zhu.ttwords.view.widget.StudyView;

import java.util.List;

public class StudyAdapter extends PagerAdapter {

    List<Object> mData;
    int mode;
    StudyListener listener;
    Context mContext;

    public StudyAdapter(Context context, List<Object> mData, int mode, StudyListener listener) {
        super();
        this.mContext = context;
        this.mData = mData;
        this.mode = mode;
        this.listener = listener;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object o) {
        return view == o;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        WordBean bean = (WordBean) mData.get(position);
        StudyView view = new StudyView(mContext);
        view.setBean(bean);
        view.setOnExamSaveListener(listener);
        if (mode == IStudyActivity.MODE_EXAM) {
            view.setExamMode();
        } else {
            view.setStudayMode();
        }
        container.addView(view);
        return view;
    }
}
